import Vue from 'vue';
import Vuex from 'vuex';
import qs from 'qs';
Vue.use(Vuex);
export default new Vuex.Store({
  state:{
    tabIcon:[true,false],
    tabIconBusiness:[true,false,false],
    minHeight:0,
    imgurlApi:'http://take.zhitiaoxiaoyuan.com', // 图片请求前缀
    userInfo:{
      score: '0',
      avatar: "../../../static/img/ren.png",
      nickname: "立即登录",
      username: '*********',
      money: '0',
      collect_goods:0,
      collect_manystore:0,
      browse:0,
      token:"",
      token_lt:'', //
    }, // 用户信息
    storeInfo:{

    }
  },
  getters:{
    userInfo:state => state.userInfo
  },
  mutations:{
    tabIcon(state,payload){
      state.tabIcon = payload
    },
    tabIconBusiness(state,payload){
      state.tabIconBusiness = payload
    },
    getScreenHeight(state,payload){
      state.minHeight = payload
    },
    signOutLogin(state){
      state.userInfo =  {
            score: '0',
            avatar: "../../../static/img/ren.png",
            nickname: "立即登录",
            username: '*********',
            money: '0',
            collect_goods:0,
            collect_manystore:0,
            browse:0,
            token:"",
            token_lt:''
      } // 用户信息
    },
    // 更新用户资料
    updateUserInfo(state,payload){
      state.userInfo[payload.type] = payload.data;
    },
    // 获取用户资料
    obtainUserInfo(state,payload){
      if (!payload){return}
      console.log(payload,'vuex38');
      $.post('http://take.zhitiaoxiaoyuan.com/index/user/head',qs.stringify({
        user_id:payload
      }),res=>{
        $.post('http://take.zhitiaoxiaoyuan.com/api/user/usemobilelogin.html',qs.stringify({
          user_id:payload
        }),data=>{
          if (res.user.avatar.length < 5) {
            res.user.avatar = '../../../static/img/ren.png';
          }
          state.userInfo = res.user;
          state.userInfo.collect_goods = res.collect_goods;
          state.userInfo.collect_manystore = res.collect_manystore;
          state.userInfo.browse = res.browse;
          state.userInfo.token_lt = data.data.userinfo.token;
          console.log(state.userInfo,511111)
        });
      })
    }
  },
  actions:{
    collectUserInfo(context,res){
      return new Promise((resolve,reject)=>{
        if (res) {

        }
      });
    }
  }
})
